#include "PreCompiled.h"
#include "point.h"

using namespace Gui;

DrawState::DrawState()
{
   DrawContext = GetCKContext(0)->GetPlayerRenderContext();
}
DrawState:: ~DrawState()
{

}
DrawPointState::DrawPointState(void)
:mMouseButtonDown(false)
{
}

void DrawPointState::mouseButtonPressedEvent(Vx2DVector& mousePos)
{
	mMouseButtonDown = true;
	mOldPosition = transMousePosToWorldPos(mousePos);
	createPoint(mOldPosition);
}
void DrawPointState::mouseButtonMoveEvent(Vx2DVector& mousePos)
{
    if(mMouseButtonDown)
	{
        VxVector cp = transMousePosToWorldPos(mousePos);
		VxVector curVector = cp - mOldPosition;  
	}
}
void DrawPointState::mouseButtonUpEvent(Vx2DVector& mousePos)
{
    mMouseButtonDown = false;
}

VxVector& DrawPointState::transMousePosToWorldPos(Vx2DVector& mousePos)
{
	VxVector pos3D;
	DrawContext->ScreenToViewpoint(mousePos,&pos3D);
	CKCamera* cam = DrawContext->GetAttachedCamera();
	cam->Transform(&pos3D,&pos3D);
	VxVector campos;
	cam->GetPosition(&campos);

	VxRay ray(campos,pos3D);

	VxVector destPos(0,-20,0);
	VxVector normalVec(0.0,-1.0,0.0);

	VxPlane p(normalVec,destPos);

	VxVector intersect;
	float dist;

	VxIntersect::RayPlane(ray,p,intersect,dist);

	return intersect;
}
void DrawPointState::createPoint(VxVector& pos)
{

}